/**
 * Created by liuyubobobo on 14-4-11.
 * my site: http://www.liuyubobobo.com
 */
function showNumberWithAnimation( i , j , text , randNumber){

    var numberCell = document.getElementById('number-cell-' + i + "-" + j );

    numberCell.style.background = getNumberBackgroundColor( randNumber );
    numberCell.style.color = getNumberColor( randNumber );

    animate(numberCell,{'width':cellSideLength,'height':cellSideLength,'top':getPosTop( i , j ),'left':getPosLeft( i , j )},4);
    var t2 = window.setTimeout(function(){
        numberCell.innerText = text;
    },300);
}
function showMoveAnimation(fromx ,fromy,tox,toy)
{

    var numberCell=document.getElementById('number-cell-'+fromx+'-'+fromy);
    animate(numberCell,{'top':getPosTop(tox,toy),'left':getPosLeft(tox,toy)},1);

    //var numberCell=$('#number-cell-'+fromx+'-'+fromy);
	//numberCell.animate(
	//{
	//	top:getPosTop(tox,toy),
	//	left:getPosLeft(tox,toy)
	//},200);
}
function updateScore(score)
{
    document.getElementById('score').innerText = score;
}

//获取对象样式规则信息，IE下使用currentStyle
function getStyle(obj,style){
    return obj.currentStyle?obj.currentStyle[style]:getComputedStyle(obj,false)[style];
}
//原生js动画类似jquery--animate
function animate(obj,styleJson,time,callback){
    clearInterval(obj.timer);
    // 开启定时器
    obj.timer=setInterval(function(){
        var flag=true;//假设所有动作都已完成成立。
        for(var styleName in styleJson){
            //1.取当前属性值
            var iMov=0;
            // 透明度是小数，所以得单独处理
            iMov=styleName=='opacity'?Math.round(parseFloat(getStyle(obj,styleName))*100):parseInt(getStyle(obj,styleName));

            //2.计算速度
            var speed=0;
            speed=(styleJson[styleName]-iMov)/15;//缓冲处理，这边也可以是固定值
            speed=speed>0?Math.ceil(speed):Math.floor(speed);//区分透明度及小数点，向上取整，向下取整

            //3.判断是否到达预定值
            if(styleJson[styleName]!=iMov){
                flag=false;
                if(styleName=='opacity'){//判断结果是否为透明度
                    obj.style[styleName]=(iMov+speed)/100;
                    obj.style.filter='alpha(opacity:'+(iMov+speed)+')';
                }else{
                    obj.style[styleName]=iMov+speed+'px';
                }
            }
        }
        if(flag){//到达设定值，停止定时器，执行回调
            clearInterval(obj.timer);
            if(callback){callback();}
        }
    },time)
}